package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author: itheima
 * @create: 2022-06-28 14:43
 */
@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API")
public class WmChannelController {

    @Autowired
    private IWmChannelService wmChannelService;


    /**
     * 根据条件分页查询频道列表
     *
     * @param dto 查询条件
     * @return 频道分页结果
     */
    @ApiOperation(value = "根据名称模糊查询分页列表", notes = "author:mcm")  // value指名称  notes 备注
    @ApiImplicitParam(name = "dto", value = "查询条件对象", required = false, dataType = "ChannelDto")
    @PostMapping("/list")
    public ResponseResult queryByPage(@RequestBody ChannelDto dto) {
        return wmChannelService.queryByPage(dto);
    }


    /**
     * 新增频道
     *
     * @param wmChannel
     * @return
     */
    @PostMapping
    public ResponseResult save(@RequestBody WmChannel wmChannel) {
        wmChannelService.saveChannel(wmChannel);
        return ResponseResult.okResult();
    }


    @GetMapping("/channels")
    public ResponseResult queryByList(){
        return wmChannelService.queryByList();
    }
}
